package com.vip.jwt.common.manager;

import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapManager implements CacheManager {

    private static Map<Object,Object> mapCache = new HashMap<>(16);

    @Override
    public <K, V> Cache<K, V> getCache(String s) throws CacheException {
        return new Cache() {
            @Override
            public Object get(Object o) throws CacheException {
                return mapCache.get(o);
            }

            @Override
            public Object put(Object o, Object o2) throws CacheException {
                return mapCache.put(o,o2);
            }

            @Override
            public Object remove(Object o) throws CacheException {
                return mapCache.remove(o);
            }

            @Override
            public void clear() throws CacheException {
                mapCache.clear();
            }

            @Override
            public int size() {
                return mapCache.size();
            }

            @Override
            public Set keys() {
                return mapCache.keySet();
            }

            @Override
            public Collection values() {
                return mapCache.values();
            }
        };
    }

}
